<template>
	<scroll ref="mescrollRef" @init="mescrollInit" :down="downOption" @down="downCallback" :up="upOption" @up="upCallback"
	 @emptyclick="emptyClick">
		<view class=" bg-gradual-blue pos-r">
			<stop bgColor="" :top="myScrollTop" :changed.sync="myRnd" bgColorFixed="bg-white" startColor="white">
				<view slot="content">ICS智慧云·生产管理系统</view>
				<view slot="left" class="fs16 pad3">
					<text class="cuIcon-scan"></text>
				</view>
				<!-- <view class="fs16 pad3" slot="right">
					<text class="cuIcon-comment"></text>
				</view> -->
			</stop>
			<view class="flrc">
				<view class="wh30-30 flcc mar5">
					<view class="fs30">0</view>
					<view class="fs12">今日任务</view>
				</view>
				<view class="wh30-30 flcc mar5">
					<view class="fs30">10</view>
					<view class="fs12">今日完成</view>
				</view>
			</view>
			<view class="pos-a b-2 l0 r0">
				<image src="../../../static/wave.gif" mode="widthFix" class="gif-wave"></image>
			</view>
		</view>
		<view class="bcf flrc pad3" @tap="$win.navto('/pages/common/message/message')">
			<view class="fs8 flrc fwb">
				<text class="c02">消息</text>
				<text class="padl2"> NEWS</text>
			</view>
			<view class="flex1 ofe padl2" v-for="message in messages">
				【{{message.title}}】{{message.content}}
			</view>
		</view>
		<view class="mart5 bcf">
			<view class="flrc padtb3">
				<view style="width: 44vw;height: 22vw;" class="pos-r marr4 round3 ofh bg-gradual-green" @tap="goto('/pages/mes/work/work')">
					<image class="posa l0 t0 r0 b0" src="../../../static/bg/bg_transparent.png" mode="widthFix"></image>
					<view class="pos-a l0 t0 r0 b0 pad5 cf lh15 flex-r flex-start">
						<view class="flex1">
							<view class="fs12 fwb">生产报工</view>
							<view class="fs8 mart1">WorkSpace</view>
						</view>
						<view class="padt3">
							<view class="fa fa-television fa-2x"></view>
						</view>
					</view>
					<ripple></ripple>
				</view>
				<view style="width: 44vw;height: 22vw;" class="pos-r round3 ofh bg-gradual-blue" 
				@tap="goto('/pages/zone/zone')">
					<image class="posa l0 t0 r0 b0" src="../../../static/bg/bg_transparent.png" mode="widthFix"></image>
					<view class="pos-a l0 t0 r0 b0 pad5 cf lh15 flex-r flex-start">
						<view class="flex1">
							<view class="fs12 fwb">信息查询</view>
							<view class="fs8 mart1">Communication</view>
						</view>
						<view class="padt2">
							<view class="fa fa-tencent-weibo fa-2x"></view>
						</view>
					</view>
					<ripple></ripple>
				</view>
			</view>
		</view>
		<!-- 考核数据 -->
		<view class="mart3 bcf pad3" v-if="isbool(reports)">
			<view class="flex1 fwb fs12 c11 list-style-2">总结计划</view>
			<view class="flrc bcf pad2 mart3">
				<view class="flex1 flrc">
					<view class="round2 ofh pos-r" @tap="goto('/pages/ciming/report/choose_action')">
						<view class="cu-btn bg-green sm">日总结 <text class="fa fa-angle-right marl1"></text></view>
						<!-- <view class="cu-btn line-green sm">{{reports.day.length}}</view> -->
						<view class="cu-btn line-green sm">
							<view v-show="reports.day.length > 0" class="fa fa-check-circle"></view>
							<view v-show="reports.day.length == 0" class="fa fa-warning c02"></view>
						</view>
						<ripple></ripple>
					</view>
				</view>
				<view class="flex1 flrc">
					<view class="round2 ofh pos-r" @tap="goto('/pages/ciming/report/choose_action')">
						<view class="cu-btn bg-green sm">周总结 <text class="fa fa-angle-right marl1"></text></view>
						<view class="cu-btn line-green sm">
							<view v-show="reports.week.length > 0" class="fa fa-check-circle"></view>
							<view v-show="reports.week.length == 0" class="fa fa-warning c02"></view>
						</view>
						<ripple></ripple>
					</view>
				</view>
				<view class="flex1 flrc">
					<view class="round2 ofh pos-r" @tap="goto('/pages/ciming/report/choose_action')">
						<view class="cu-btn bg-green sm">月总结 <text class="fa fa-angle-right marl1"></text></view>
						<view class="cu-btn line-green sm">
							<view v-show="reports.month.length > 0" class="fa fa-check-circle"></view>
							<view v-show="reports.month.length == 0" class="fa fa-warning c02"></view>
						</view>
						<ripple></ripple>
					</view>
				</view>
			</view>
			
			<view class="flex1 fwb fs12 c11 list-style-2 mart3">工作量统计</view>
			<view class="flrc padtb5 fwb tac" v-if="isbool(sales)">
				<view class="flex1 flcc">
					<view class="fs14">{{sales.day}}</view>
					<view>今天</view>
				</view>
				<view class="flex2">
					<view class="fs14">{{sales.month}} / <text class="fwn fs10 padl2">{{sales.monthTarget}}</text></view>
					<view>本月</view>
				</view>
				<view class="flex2">
					<view class="fs14">{{sales.year}} / <text class="fwn fs10 padl2">{{sales.yearTarget}}</text></view>
					<view>年度</view>
				</view>
			</view>
		</view>
		<view class="mart5 bcf">
			<view class="pad3 flrc pos-r" @tap="goto('/pages/common/work_space/work_space_select')">
				<view class="flex1 fwb fs12 c11 list-style-2">常用功能</view>
				<view class="c03 fs14"><text class="fa fa-cog marl2"></text></view>
				<ripple></ripple>
			</view>
			<view class="flex-r flex-wrap flex-start mart3">
				<view class="w25  c13 flcc padb3 pos-r" @tap="goto(item.action)" v-for="item in workSpaceLocalData">
					<view class=" wh15-15 round3 shadow flcc pos-r">
						<!-- <text class="fa fa-cubes fa-2x"></text> -->
						<view>
							<image :src="pic(item.pic)" mode="aspectFill" class="wh10-10"></image>
						</view>
					</view>
					<view class="mart1 c11">{{item.name}}</view>
					<ripple-black></ripple-black>
				</view>
			</view>

			<view v-if="workSpaceLocalData.length === 0" class="pad2 tac">
				<view class="pad7 bdda bc13 pos-r" @tap="goto('/pages/common/work_space/work_space_select')">
					未选择任何功能
					<ripple></ripple>
					</view>
			</view>
		</view>
		<view class="mart5 bcf">
			<view class="pad3 flrc pos-r" @tap="goto('/pages/machine/my_focus')">
				<view class="flex1 fwb fs12 c11 list-style-2">常用设备</view>
				<view class="c03 fs14"><text class="fa fa-cog marl2"></text></view>
				<ripple></ripple>
			</view>
		</view>
		<view class="mart5 bcf">
			<view class="pad3 flrc">
				<view class="flex1 fwb fs12 c11 list-style-2">文章分享</view>
			</view>
			<view v-for="item,index in art" :key="item.id">
				<view class="cu-card case no-card mart1 ripple" 
				@tap="goto('/pages/common/art/art_info?id=' + item.id)">
					<view class="cu-item shadow">
						<view class="image">
							<image :src="$api.getAssetBaseUrl() + item.cover" mode="widthFix"></image>
							<!-- <view class="cu-tag bg-blue">史诗</view> -->
							<!-- <view class="cu-bar bg-shadeBottom"> 
							<text class="text-cut">
								{{item.title}}
							</text>
							</view> -->
						</view>
						<view class="cu-list menu-avatar">
							<view class="cu-item">
								<!-- <view class="cu-avatar round lg" style="background-image:url(https://ossweb-img.qq.com/images/lol/web201310/skin/big10006.jpg);"></view> -->
								<view class="flex-sub lh2 padlr5">
									<view class="text-grey">【{{item.category.name}}】{{item.title}}</view>
									<view class="text-gray text-sm flex justify-between">
										{{$com.str2time(item.createAt)}}
										<view class="text-gray text-sm">
											<text class="cuIcon-attentionfill margin-lr-xs"></text> {{item.numView}}
									<!-- 		<text class="cuIcon-appreciatefill margin-lr-xs"></text> 20
											<text class="cuIcon-messagefill margin-lr-xs"></text> 30 -->
										</view>
									</view>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>

		</view>

		<loading :loading="myIsLoading"></loading>
	</scroll>
</template>

<script>
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
	import List from '../../../assets/js/list.js'
	let list = new List()
	export default {
		components:{},
		mixins: [MescrollMixin],
		data() {
			return {
				rnd: 0,
				workSpaceLocalData: [],
				machinesFocusLocalData: [],
				art: [],
				messages:[],
				reports:'',
				sales:'',
			}
		},
		mounted() {
			this.myIsLoading = false
			list.initMescroll(this).setUrl('/api/articles').setCbFunc(res => {
				this.art = res
				this.clearLoading()
			}).getList()

		},
		methods: {
			getIndexData(){
				this.$api.get('/api/ciming/index',{},res=>{
					this.log(res)
					this.messages = res.d.messages
				})
			},
			getReportData(){
				this.$api.get('/api/cur/cimingReports',{},res=>{
					this.log(res)
					this.reports = res.d
				})
			},
			getSalesData(){
				this.$api.get('/api/me/kpiUserSalesLogs',{},res=>{
					this.log(res)
					this.sales = res.d
				})
			}
		},
		onLoad(option) {

		},
		onShow() {
			if (!this.$com.isLogin()) {
				this.goto("/pages/user/phoneLogin")
			} else {
				this.log('user already login')
			}
			//检查滚动值
			this.myRnd = Math.random()
			this.log("on show")

			let workSpaceLocalData = this.$com.getLocDataObject("workSpaceLocalData")
			if (this.isbool(workSpaceLocalData)) {
				//检查数据是否有变动
				if(workSpaceLocalData === this.workSpaceLocalData){
					this.log("nochange")
				}else{
					this.workSpaceLocalData = workSpaceLocalData
				}
			}else{
				this.workSpaceLocalData = []
			}

			let machinesFocusLocalData = this.$com.getLocDataObject("machinesFocusLocalData")
			if (this.isbool(machinesFocusLocalData)) {
				this.machinesFocusLocalData = machinesFocusLocalData
			}else{
				this.machinesFocusLocalData = []
			}
			
			
			//获取首页数据
			this.getIndexData()
			this.getReportData()
			this.getSalesData()
		}
	}
</script>

<style>
	.gif-wave {
		position: absolute;
		width: 100%;
		bottom: 0;
		left: 0;
		z-index: 99;
		mix-blend-mode: screen;
		height: 100rpx;
		display: block;
	}
</style>
